package com.psq.psq

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.psq.core.common.provider.IMainProvider
import com.psq.core.common.provider.ROUTER_MAIN_PROVIDER
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean

@SuppressLint("CustomSplashScreen")
class SplashActivity : AppCompatActivity() {

    private var keepOnScreen = AtomicBoolean(true)

    override fun onCreate(savedInstanceState: Bundle?) {
        val splashScreen = installSplashScreen()
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        lifecycleScope.launch {
            delay(2000)
            keepOnScreen.compareAndSet(true, false)
        }
        splashScreen.setKeepOnScreenCondition { keepOnScreen.get() }

        val provider =
            ARouter.getInstance().build(ROUTER_MAIN_PROVIDER).navigation() as IMainProvider
        provider.navHome()
        finish()
    }
}